using MicroMsg.Common.Utils;
using System;
using System.Collections.Generic;
namespace MicroMsg.Storage
{
	public class StorageBasic
	{
		private static List<IStorageLogin> loginNotifyList = new List<IStorageLogin>();
		private static List<IStorageFlush> flushNotifyList = new List<IStorageFlush>();
		public static void registerLoginNotify(IStorageLogin storage)
		{
			StorageBasic.loginNotifyList.Add(storage);
		}
		public static void registerFlushNotify(IStorageFlush flush)
		{
			StorageBasic.flushNotifyList.Add(flush);
		}
		public static void onFlush()
		{
			Log.smethod_5("storage", "flush all begin");
			using (List<IStorageFlush>.Enumerator enumerator = StorageBasic.flushNotifyList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					IStorageFlush current = enumerator.get_Current();
					current.onFlush();
				}
			}
			Log.smethod_5("storage", "flush all end");
		}
		public static void onLogin(string usrName)
		{
			if (string.IsNullOrEmpty(usrName))
			{
				throw new Exception(" login invalid usrName!");
			}
			DebugEx.getTimeSpan(0L);
			StorageIO.initUserDataDir(usrName);
			StorageDB.init(StorageIO.getDatabasePath());
			DebugEx.getTimeSpan(0L);
			using (List<IStorageLogin>.Enumerator enumerator = StorageBasic.loginNotifyList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					IStorageLogin current = enumerator.get_Current();
					current.onLogin(usrName);
					DebugEx.getTimeSpan(0L);
				}
			}
		}
		public static void onLogout()
		{
			StorageBasic.loginNotifyList.Reverse();
			using (List<IStorageLogin>.Enumerator enumerator = StorageBasic.loginNotifyList.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					IStorageLogin current = enumerator.get_Current();
					current.onLogout();
				}
			}
			StorageBasic.loginNotifyList.Reverse();
			StorageDB.uninit();
		}
	}
}
